function getdev(){
  devid=$crypto.digest(device.fingerprint+device.serial+device.getMacAddress()+device.getAndroidId(), "MD5")

  return devid
 }
 devid=getdev()
 function login(){
  var url = "http://124.223.0.9:3000/api/login";

var res = http.post(url, {
	"username": devid,
	"password":'147258'
});
var html = res.body.json()
log(html)
token=html.token
if (res.statusCode==422){//未注册的
  sign()
}else if (html.user.deviceNum==0){
  log('请授权！')
//   var name = rawInput("请输入授权码");
// if (name.length<8){
// toastLog('请输入正确的授权码！！！')
// exit()
// }
rawInput("请输入授权码", "", a => {
  if (!a){
    toastLog('请输入正确的授权码！！！')
    exit()
  }
key=a
});
signkey(key)
}else{
  toastLog('登录成功')
}
 }
 function sign(){
  var url = "http://124.223.0.9:3000/api/sign";

  var res = http.post(url, {
    "username": devid,
    "password":'147258'
  });
  var html = res.body.string();
  if (html=='注册成功，请联系管理员审核'){
    login()
  }
 
 }
 function signkey(key){
  var url = "http://124.223.0.9:3000/api/signkey";

  var res = http.post(url, {
    "username": devid,
    "password":'147258',
    "key":key
  },{
    headers: {
      "Authorization": 'Bearer '+token 
    }
  
  });

  var html = res.body.string();

 if (res.statusCode!=200){
  toastLog(html)
  exit()
 }
 toastLog(html)
 }
 login()